<template>
  <div id="main"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: {
    sendOption: {
      type: Object,
      required: true,
    },
  },
  watch: {
    sendOption: {
      deep: true,
      handler() {
        this.query();
      },
    },
  },
  methods: {
    query() {
      let option = {
        title: {
          text: this.sendOption.title,
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          data:this.sendOption.legend,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data:this.sendOption.xAxis,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: this.sendOption.series
      };
      var myChart = echarts.init(document.getElementById("main"));
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
  },
};
</script>

<style lang="less" scoped></style>
